package com.example.bmanliku;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListActivity extends AppCompatActivity {
    private LinearLayout ShowTag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        Bundle bundle = getIntent().getExtras();
        String TagList = bundle.getString("TagList");

        //test
        final String[] lst = TagList.split("[$$]");
        for (int i = 0; i < lst.length; i++)
            System.out.println(lst[i]);

        //initialize
        ShowTag = findViewById(R.id.ShowTag);
        for (int i = 0; i < lst.length; i++) {
            final TextView textView = new TextView(this);


            String display = lst[i].replace("\\n", "\n");
            textView.setText(Html.fromHtml(display));
            // TODO: 2020/12/31 textview css美化

            //显示最大行数1行作为标签
            textView.setMaxLines(1);

            final int finalI = i;
            textView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("detail", lst[finalI]);
                    Intent intent=new Intent(ListActivity.this,DetailActivity.class);
                    intent.putExtras(bundle);
                    finish();
                    startActivity(intent);
                }
            });
            ShowTag.addView(textView);
        }
    }
}